﻿@model ZSZ.DTO.AdminUserDTO[]
@{
    ViewBag.Title = "管理员列表";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

@section headjs{
    <link href="~/css/style.css" rel="stylesheet" type="text/css" />
    <link href="~/lib/Hui-iconfont/1.0.1/iconfont.css" rel="stylesheet" type="text/css" />
    <!--[if IE 6]>
    <script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
}


<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 管理员管理 <span class="c-gray en">&gt;</span> 管理员列表 <a class="btn btn-success radius r mr-20" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新"><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="pd-20">
    <div class="cl pd-5 bg-1 bk-gray mt-20"> <span class="l"><a href="javascript:;" onclick="datadel()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a> <a href="javascript:;" onclick="admin_add('添加管理员','/AdminUser/Add','800','500')" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 添加管理员</a></span> <span class="r">共有数据：<strong>@Model.Length</strong> 条</span> </div>
    <form id="perList">
        <table class="table table-border table-bordered table-bg">
            <thead>
                <tr>
                    <th scope="col" colspan="9">管理员列表</th>
                </tr>
                <tr class="text-c">
                    <th width="25"><input type="checkbox" name="" value=""></th>
                    <th width="150">名字</th>
                    <th width="90">手机号</th>
                    <th width="90">邮箱</th>
                    <th width="90">城市</th>
                    <th width="100">操作</th>
                </tr>
            </thead>
            <tbody>
                @foreach (var item in Model)
                {
                    <tr class="text-c">
                        <td><input type="checkbox" value="@item.Id" name="adminUserIds"></td>
                        <td>@item.Name</td>
                        <td>@item.PhoneNum</td>
                        <td>@item.Email</td>
                        @if (item.CityID == null)
                        {
                            <td>总部</td>
                        }
                        else {
                            <td>@item.CityName</td>
                        }
                        <td class="td-manage">
                            <a title="编辑" href="javascript:;" onclick="admin_edit('管理员编辑','/AdminUser/Edit/@item.Id','1','800','500')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a>
                            <a title="删除" href="javascript:;" onclick="admin_del(this,@item.Id)" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a>
                        </td>
                    </tr>
                }
            </tbody>
        </table>
    </form>
</div>
@section footerjs{
    <script type="text/javascript">
        /*
            参数解释：
            title	标题
            url		请求的url
            id		需要操作的数据id
            w		弹出层宽度（缺省调默认值）
            h		弹出层高度（缺省调默认值）
        */
        /*管理员-增加*/
        function admin_add(title, url, w, h) {
            layer_show(title, url, w, h);
        }
        /*管理员-删除*/
        function admin_del(obj, id) {
            layer.confirm('确认要删除吗？', function (index) {
                //此处请求后台程序，下方是成功后的前台处理……
                $.ajax({
                    url: '/AdminUser/DeletedById/' + id,
                    dataType: 'json',
                    type: 'post',
                    success: function (ss) {
                        if (ss.status == 'ok') {
                            $(obj).parents("tr").remove();
                            layer.msg('已删除!', { icon: 1, time: 1000 });
                        } else {
                            alert(ss.errorMsg);
                        }
                    },
                    error: function () {
                        alert("请求失败");
                    }
                })
            });
        }
        /*管理员-编辑*/
        function admin_edit(title, url, id, w, h) {
            layer_show(title, url, w, h);
        }

        function datadel() {
            var formData = $('#perList').serializeArray();
            $.ajax({
                url: '/AdminUser/DeleteByIds',
                dataType: "json",
                type: 'post',
                data: formData,
                success: function (res) {
                    if (res.status == 'ok') {
                        window.location.reload();
                    } else {
                        alert(res.errorMsg);
                    }
                },
                error: function () {
                    alert("网络请求错误");
                }
            });
        }
    </script>
}


